package com.myq.note.util;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class UserProxy {

    @Pointcut("execution(* com.myq.note.service.*.*(..))")
    // 使用一个返回值为void、方法体为空的方法来命名切入点
    private void myPointCut() {
    }


    @Before(value = "myPointCut()")
    public void beFore(){
        //System.out.println("beFore");
    }

    @AfterReturning(value = "execution(* com.myq.note.service.*.*(..))")
    public void myAfterReturning(JoinPoint joinPoint) {
        //System.out.print("后置通知");
        //System.out.println("被织入增强处理的目标方法为：" + joinPoint.getSignature().getName());
    }

    @Around("execution(* com.myq.note.service.*.*(..))")
    public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        long l = System.currentTimeMillis();
        // 开始
        System.out.println("环绕开始：执行目标方法之前，模拟开启事务...");
        // 执行当前目标方法
        Object obj = proceedingJoinPoint.proceed();
        // 结束
        long l1 = System.currentTimeMillis();
        System.out.println("环绕结束该方法执行时间为："+(l1-l));

        return obj;
    }

    @After("myPointCut()")
    public void myAfter() {
        //System.out.println("最终通知：模拟方法结束后的释放资源...");
    }




}
